package com.badlogic.androidgames.mrnom;

import java.io.OutputStreamWriter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class ActiveSnake extends Activity implements OnClickListener {

    private final static String NOTES = "notes.txt";
    Button btnOK;
    EditText txtActive;
    Button btnExit;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        btnOK = (Button) findViewById(R.id.btnActive);
        btnExit = (Button) findViewById(R.id.btnExit);
        txtActive = (EditText) findViewById(R.id.txtEActive);
        btnOK.setOnClickListener(this);
        btnExit.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        if (v.equals(btnOK)) {
            // nhap so active code

            if ((txtActive.getText().toString().equals("111"))) {

                // ghi nho chuong trinh da Active
                writeFile();

                Intent intentMy = new Intent(ActiveSnake.this, MrNomGame.class);
                startActivity(intentMy);
            }
        } else if (v.equals(btnExit)) {
            onDestroy();
        }

    }

    public boolean writeFile() {
        try {
            OutputStreamWriter out = new OutputStreamWriter(openFileOutput(NOTES, 0));

            out.write("1");
            out.close();
        } catch (Throwable t) {
            Toast.makeText(this, "Exception: " + t.toString(), 2000).show();
            return false;// that bai
        }
        return true;// thanh cong
    }

}